﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Login;
using Login.Models;
using Login.Common;

namespace Login.Controllers
{
    public class UserController : Controller
    {
        PracticeEntities1 Entity = new PracticeEntities1();
        [HttpPost]
        public ActionResult Login(UserModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.UserName == null || model.Password == null)
                    return View();
                model.Password = Encryp.GetMd5String16Low(model.Password);
                List<User> user = Entity.User.Where(a => a.UserName == model.UserName && a.Password == model.Password).ToList();
                if (user.Count != 1)
                {
                    ViewBag.ErroMes = "账号密码错误";
                    return View();
                }
                Response.Cookies["ID"].Value =Encryp.DesEncrypt(user[0].ID.ToString());
                return Redirect("successfulLogon");
            }
            return View();
        }
        [HttpGet]
        public ActionResult login()
        {
            return View();
        }
        public ActionResult SuccessfulLogon()
        {
               return View();
        }
    }
}